
export function timestampToDaysAgo(timestamp) {
    const oneDay = 24 * 60 * 60 * 1000; // 每天的毫秒数
    const now = new Date().getTime(); // 当前时间的毫秒表示
    const difference = now - timestamp; // 计算时间差
    return Math.round(difference / oneDay); // 返回差值转换成天数的结果
}

export function compareTimestamp(timestamp){
	const currentTime = new Date().getTime();
	const timeDiff = currentTime - timestamp;
	if(timeDiff<60000){
		return'1分钟内';
	}else if(timeDiff< 3600000){
		return Math.floor(timeDiff / 60000)+'分钟';
	}else if(timeDiff < 24 * 60 * 60 * 1000){
		return Math.floor(timeDiff / 3600000)+'小时';
	}else if(timeDiff< 30 * 24 * 60 * 60 * 1000){
		return Math.floor(timeDiff / 86400000)+'天';
	}else if(timeDiff < 12 * 30 * 24 * 60 * 60 * 1000){
		return Math.floor(timeDiff / 2592000000)+'月';
	}else if(timeDiff < 5 * 12 * 30 * 24 * 60 * 60 * 1000){
		return Math.floor(timeDiff / 31104000000)+'年';
	}else {
	    return null;
	}
}

export function gotoHome(){
	uni.showModal({
		title:"提示",
		content:"页面有误将返回首页",
		showCancel:false,
		success:(res)=>{
			uni.reLaunch({
				url:"/pages/index/index"
			})
		}
	})
}